﻿namespace SERFLITEMAX20.Core
{
    using SERFLITEMAX20;
    using System;

    public class UnitObject : UnitBase
    {
        private string subname;

        public UnitObject(int ptr, Main sender) : base(ptr, sender)
        {
            this.Update();
        }

        public override bool Update()
        {
            bool flag = base.Update();
            if (flag)
            {
                if (base.Type != enObjectTypes.Unit)
                {
                    return flag;
                }
                int num = base.sender.Memory.ReadInteger(base.ptrBase + Addresses.OFFSET_UNIT_Name_DB);
                if (num <= 0)
                {
                    return flag;
                }
                int address = base.sender.Memory.ReadInteger(num + Addresses.OFFSET_UNIT_Name);
                if (address > 0)
                {
                    base.name = base.sender.Memory.ReadString(address, 0x40);
                }
                int num3 = base.sender.Memory.ReadInteger(num + Addresses.OFFSET_UNIT_SubName);
                if (num3 > 0)
                {
                    this.subname = base.sender.Memory.ReadString(num3, 0x40);
                }
            }
            return flag;
        }

        public override bool IsSkinnable
        {
            get
            {
                return ((this.Flags & 0x4000000) != 0);
            }
        }

        public override string Name
        {
            get
            {
                if (base.name != null)
                {
                    if ((this.subname != null) && (this.subname.Length > 0))
                    {
                        return (base.name + "<" + this.subname + ">");
                    }
                    return base.name;
                }
                return "";
            }
        }

        public override string SubName
        {
            get
            {
                return this.subname;
            }
        }
    }
}

